package engine

import (
	"fmt"
	"github.com/dop251/goja"
	"github.com/dop251/goja_nodejs/eventloop"
)

var Engine *goja.Runtime
var Path string

func StartEngine(path string) {
	Path = path
	loop := eventloop.NewEventLoop()
	loop.Run(func(runtime *goja.Runtime) {
		Engine = runtime
	})
	InitEngineFunction()
	loop.Start()
}

func Exec(script string) {
	_, err := Engine.RunString(script)
	if err != nil {
		fmt.Println(err)
	}
}
